
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
limiter-component
Advanced tools
Limits the rate of function calls to one per period. It delays but does not throttle the calls.
Limits the rate of function calls to one per period. It delays but does not throttle the calls. Useful when your codes needs to behave well when calling rate limited API.
If you need something more flexible use rate limiter
$ npm install --save limiter-component
Create limiter
with desired interval
setting. Call trigger
passing a function that you want to
limit.
var limiter = require('limiter'),
l = limiter(500); // interval in millis
function doThis() {
// this is called at most twice per second
}
function doThat() {
// you can rate limit different functions
}
l.trigger(doThis);
l.trigger(doThat);
l.trigger(doThis);
l.trigger(function() {
l.penalty(); // wait a bit longer the next time
});
l.trigger(doThat);
l.trigger(function() {
l.skip(); // don't wait at all the next time
});
l.trigger(doThis);
// you can also wait for the trigger using Promises
await l.trigger(); // note that `fn` is optional
// trigger has been resolved
Create limiter
with desired interval
(in millis). Optional penaltyInterval
is used instead of
interval
if limiter.penalty()
has been called at least once since last limited function has been
triggered.
Add fn
to limiter
queue. It will be called when interval
elapsed since another function from
the queue was called. Returns a promise, which is resolved when fn
is called.
Make limiter use penaltyInterval
before triggering next function.
Make limiter trigger next function immediately.
Empty limiter
queue. Remove all pending trigger request. No methods from the queue is called after
cancel
.
MIT
FAQs
Limits the rate of function calls to one per period. It delays but does not throttle the calls.
We found that limiter-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.